<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\recruitment\model;

use app\cassification\model\ClassificationDictionary;
use app\Cnarea\model\Cnarea;
use app\recruitmentEnterprise\model\recruitmentEnterprise;
use Illuminate\Support\Facades\DB;
use plugin\saiadmin\basic\BaseNormalModel;

/**
 * 招聘列表模型
 */
class recruitment extends BaseNormalModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'recruitment_id';

    /**
     * 数据库表名称
     * @var string
     */
    protected $table = 'eb_recruitment';

    protected $append = ['province_id_text','city_id_text','district_id_text','work_experience_text','education_requirement_text','enterprise_id_text','salary_range_text','enterprise_size_text'];
    /**
     * 职位名称 搜索
     */
    public function searchPositionNameAttr($query, $value)
    {
        $query->where('position_name', 'like', '%'.$value.'%');
    }
    public function getProvinceIdTextAttr($value,$data){
        if(isset($data['province_id'])){
            $value=Cnarea::where('area_code',$data['province_id'])->value('name');
            if(!$value)$value='全国';
        }else{
            $value='全国';
        }
        return $value;
    }
    public function getCityIdTextAttr($value,$data){

        if(isset($data['city_id'])){
            $value=Cnarea::where('area_code',$data['city_id'])->value('name');
            if(!$value)$value='全省';
        }else{
            $value='全省';
        }
        return $value;
    }

    public function getDistrictIdTextAttr($value,$data){
        if(isset($data['district_id'])){
            $value=Cnarea::where('area_code',$data['district_id'])->value('name');
            if(!$value)$value='全市';
        }else{
            $value='全市';
        }
        return $value;
    }
    public function getWorkExperienceTextAttr($value,$data)
    {
        if($data['work_experience']){
            return    ClassificationDictionary::where('dictionary_id', $data['work_experience'])->value('classification_name_zh');
        }
        return $value;
    }

    public function getEducationRequirementTextAttr($value,$data)
    {
        if(isset($data['education_requirement'])){
            return    ClassificationDictionary::where('dictionary_id', $data['education_requirement'])->value('classification_name_zh');
        }
        return $value;
    }
    public function getSalaryRangeTextAttr($value,$data)
    {

        if(isset($data['salary_range'])){
            return    ClassificationDictionary::where('dictionary_id', $data['salary_range'])->value('classification_name_zh');
        }
        return $value;
    }


    public function getEnterpriseIdTextAttr($value,$data)
    {
        if(isset($data['enterprise_id'])) {
            return recruitmentEnterprise::where('enterprise_id', $data['enterprise_id'])->value('enterprise_name');
        }
        return $value;
    }
    public function getEnterpriseSizeTextAttr($value,$data)
    {
        if(isset($data['enterprise_id'])) {
            return recruitmentEnterprise::where('enterprise_id', $data['enterprise_id'])->value('enterprise_size');
        }
        return $value;
    }
}
